package model.db;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Data;

/**
 * Author: Raoux Etienne
 * Student login: jc218934
 * Student number: 12448190
 * email: etienne.raoux@my.jcu.edu.au
 * alt email: jc218934@gmail.com
 */
public class OurConnection
{
    private static Connection connection = null;

    public static Connection connect()
    {

        if (connection != null)
        {
            try 
            {
                while (connection.isClosed())
                {
                    Class.forName("org.sqlite.JDBC");
                    return DriverManager.getConnection("jdbc:sqlite:"+Data.dbFile);
                }
            } 
            catch (Exception ex) 
            {
                Logger.getLogger(OurConnection.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        try
        {
            Class.forName("org.sqlite.JDBC");
            connection = DriverManager.getConnection("jdbc:sqlite:"+Data.dbFile);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }

        return connection;
    }
}
